<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>页面显示时间</title>
    <style>
        div {
            width: 300px;
            height: 40px;
            border: 1px solid pink;
            text-align: center;
            line-height: 40px;
        }
    </style>
</head>
<div></div>
<body>
<script>

    setInterval(function () {
        var data = new Date
        var year = data.getFullYear();
        var month = data.getMonth() + 1;
        var day = data.getDate();
        var hour = data.getHours();
        var minutes = data.getMinutes()
        var seconds = data.getSeconds();

        //获取框
        var input = document.querySelector("div");
        input.innerHTML = `今天是${year}年${month}月${day}日${hour}-${minutes}-${seconds}`
    }, 1000)
</script>
</body>
</html>